package com.company.project.web;
import com.company.project.core.Result;
import com.company.project.core.ResultGenerator;
import com.company.project.model.ThesisGuide;
import com.company.project.service.ThesisGuideService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
* Created by CodeGenerator on 2018/10/09.
*/
@RestController
@RequestMapping("/thesisguide")
public class ThesisGuideController {
    @Resource
    @Autowired
    private ThesisGuideService thesisGuideService;
    //投稿指南
    @RequestMapping(value = "/fingerpost",method = RequestMethod.GET)
    @ResponseBody
    public List<Map<String,Object>> selectThesisGuide(){
        List<Map<String, Object>> maps = thesisGuideService.selectThesisGuide();
        return maps;
    }

    /**
     * 修改投稿指南
     * @param thesisGuide
     * @return
     */
    @PostMapping("/updateTG")
    @ResponseBody
    public Result updateTG(@RequestBody ThesisGuide thesisGuide){
        Boolean aBoolean = thesisGuideService.updateTG(thesisGuide);
        return ResultGenerator.genSuccessResult(aBoolean);
    }

    @PostMapping("/add")
    public Result add(ThesisGuide thesisGuide) {
        thesisGuideService.save(thesisGuide);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/delete")
    public Result delete(@RequestParam Integer id) {
        thesisGuideService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(ThesisGuide thesisGuide) {
        thesisGuideService.update(thesisGuide);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        ThesisGuide thesisGuide = thesisGuideService.findById(id);
        return ResultGenerator.genSuccessResult(thesisGuide);
    }

    @PostMapping("/list")
    public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<ThesisGuide> list = thesisGuideService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }
}
